Repository Public
1import { sql } from "@/lib/db";2import { OpError } from "@/lib/studio-ops";3import { isUuid, out, studio } from "@/lib/studio-api";45/** GET /api/studio/jobs/:id — a pipeline stage run with the provider calls it made (state, attempts, errors, cost). */6export async function GET(req: Request, ctx: { params: Promise<{ id: string }> }) {7 const { id } = await ctx.params;8 return studio(req, "viewer", async () => {9 if (!isUuid(id)) throw new OpError("Job not found", 404);10 const [run] = await sql`SELECT id, project_id, stage, status, attempts, error, queued_at, started_at, finished_at FROM stage_runs WHERE id = ${id}`;11 if (!run) throw new OpError("Job not found", 404);12 const calls = await sql`13 SELECT id, kind, model, status, attempts, error, est_usd, cost_usd, cost_source, request_id, created_at, finished_at14 FROM provider_jobs WHERE project_id = ${run.project_id} AND stage = ANY(${run.stage === "script" ? ["script", "research"] : [run.stage as string]}) AND created_at >= ${run.queued_at}::timestamptz - interval '1 second'15 ORDER BY created_at`;16 return out({ job: run, providerCalls: calls });17 });18}19